﻿using System;
using SoftwareMonkeys.LogClimber.Entities;
using System.Collections.Generic;

namespace SoftwareMonkeys.LogClimber.Controls
{
	/// <summary>
	/// Description of ComponentsExtractor.
	/// </summary>
	public class ComponentsExtractor
	{
		static public string[] GetComponentNames(Log log)
		{
			if (log == null)
				throw new ArgumentNullException("log");
			
			List<string> list = new List<string>();
			
			foreach (Entry entry in log.ChildEntries)
			{
				foreach (string component in GetComponentNames(entry))
				{
					if (!list.Contains(component))
						list.Add(component);
				}
			}
			
			return list.ToArray();
		}
		
		static public string[] GetComponentNames(Entry entry)
		{
			List<string> list = new List<string>();
			
				if (!list.Contains(entry.Component))
					list.Add(entry.Component);
				
			foreach (Entry childEntry in entry.ChildEntries)
			{
				foreach (string component in GetComponentNames(childEntry))
				{
					if (!list.Contains(component))
						list.Add(component);
				}
			}
			
			return list.ToArray();
		}
	}
}
